package cn.ad.server.persistence.dao;

import java.util.List;

import cn.ad.server.domain.ad.Campaign;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

@Component
public interface CampaignDao {

	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "start_time", property = "startTime"), @Result(column = "end_time", property = "endTime"),
			@Result(column = "advertiser_id", property = "advertiser.id"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
			@Result(column = "industry_id", property = "industry.id"),
			@Result(column = "unit_price", property = "unitPrice"), @Result(column = "fee_type", property = "feeType"),
			@Result(column = "budget_day", property = "budgetDay"),
			@Result(column = "max_impressions", property = "maxImpressions"),
			@Result(column = "day_impressions", property = "dayImpressions"),
			@Result(column = "max_clicks", property = "maxClicks"),
			@Result(column = "day_clicks", property = "dayClicks") })
	@Select("select * from campaign")
	List<Campaign> findAll();

	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "start_time", property = "startTime"), @Result(column = "end_time", property = "endTime"),
			@Result(column = "advertiser_id", property = "advertiser.id"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
			@Result(column = "industry_id", property = "industry.id"),
			@Result(column = "unit_price", property = "unitPrice"), @Result(column = "fee_type", property = "feeType"),
			@Result(column = "budget_day", property = "budgetDay"),
			@Result(column = "max_impressions", property = "maxImpressions"),
			@Result(column = "day_impressions", property = "dayImpressions"),
			@Result(column = "max_clicks", property = "maxClicks"),
			@Result(column = "day_clicks", property = "dayClicks") })
	@Select("select * from campaign where update_time >= #{value}")
	List<Campaign> findAfterTime(String warmUpTime);

	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "start_time", property = "startTime"), @Result(column = "end_time", property = "endTime"),
			@Result(column = "advertiser_id", property = "advertiser.id"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
			@Result(column = "industry_id", property = "industry.id"),
			@Result(column = "unit_price", property = "unitPrice"), @Result(column = "fee_type", property = "feeType"),
			@Result(column = "budget_day", property = "budgetDay"),
			@Result(column = "max_impressions", property = "maxImpressions"),
			@Result(column = "day_impressions", property = "dayImpressions"),
			@Result(column = "max_clicks", property = "maxClicks"),
			@Result(column = "day_clicks", property = "dayClicks") })
	@Select("select * from campaign where id = #{value}")
	Campaign findById(int id);

	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "start_time", property = "startTime"), @Result(column = "end_time", property = "endTime"),
			@Result(column = "advertiser_id", property = "advertiser.id"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
			@Result(column = "industry_id", property = "industry.id"),
			@Result(column = "unit_price", property = "unitPrice"), @Result(column = "fee_type", property = "feeType"),
			@Result(column = "budget_day", property = "budgetDay"),
			@Result(column = "max_impressions", property = "maxImpressions"),
			@Result(column = "day_impressions", property = "dayImpressions"),
			@Result(column = "max_clicks", property = "maxClicks"),
			@Result(column = "day_clicks", property = "dayClicks") })
	@Select("select * from campaign where id = #{id} and status = #{status}")
	Campaign selectById(@Param("id") long id, @Param("status") int status);

	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "start_time", property = "startTime"), @Result(column = "end_time", property = "endTime"),
			@Result(column = "advertiser_id", property = "advertiser.id"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
			@Result(column = "industry_id", property = "industry.id"),
			@Result(column = "unit_price", property = "unitPrice"), @Result(column = "fee_type", property = "feeType"),
			@Result(column = "budget_day", property = "budgetDay"),
			@Result(column = "max_impressions", property = "maxImpressions"),
			@Result(column = "day_impressions", property = "dayImpressions"),
			@Result(column = "max_clicks", property = "maxClicks"),
			@Result(column = "day_clicks", property = "dayClicks") })
	@Select("select * from campaign where status = 1")
	List<Campaign> findAvailable();
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "start_time", property = "startTime"), @Result(column = "end_time", property = "endTime"),
			@Result(column = "advertiser_id", property = "advertiser.id"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
			@Result(column = "industry_id", property = "industry.id"),
			@Result(column = "unit_price", property = "unitPrice"), @Result(column = "fee_type", property = "feeType"),
			@Result(column = "budget_day", property = "budgetDay"),
			@Result(column = "max_impressions", property = "maxImpressions"),
			@Result(column = "day_impressions", property = "dayImpressions"),
			@Result(column = "max_clicks", property = "maxClicks"),
			@Result(column = "day_clicks", property = "dayClicks") })
	@Select("select * from campaign where  id = #{id} and status = 1 and end_time > now()")
	Campaign findAvailableById(int id);

}
